package uk.org.landeg.euler.problems;

import java.util.ArrayList;

import uk.org.landeg.euler.problems.framework.AbstractProblem;
import uk.org.landeg.euler.problems.framework.ProblemLauncher;
import uk.org.landeg.euler.problems.lib.NumbersLib;

public class Problem055 extends AbstractProblem {
	long numlens[] = new long [] {1,10,100,1000,10000,100000,1000000,10000000,100000000,1000000000,10000000000L,100000000000L};
	public static void main(String[] args) {
		ProblemLauncher launcher = new ProblemLauncher(new Problem055());
		launcher.solve();		
	}
	@Override
	public String getDescription() {
		// TODO Auto-generated method stub
		return "How many Lychrel numbers are there below ten-thousand?";
	}
	@Override
	public Integer getProblemNumber() {
		// TODO Auto-generated method stub
		return 55;
	}
	@Override
	public Object solve() {
		notes.add("Perhaps a common issue with this problem is ignoring the clause; ");
		notes.add("\"Surprisingly, there are palindromic numbers that are themselves Lychrel numbers\"");
		notes.add("It's important to do the 'reverse/add' before testing for palindrome");
		int count = 0;
//		BigInteger test;
		long test;
		ArrayList<Integer> lychNumbers = new ArrayList<Integer>();
		boolean isLych;
		System.out.println(Long.MAX_VALUE);
		for (int n = 1; n < 10000 ; n++) {
			isLych = true;
//			test = BigInteger.valueOf(n);
			test = n;
			for (int itt = 0 ; itt <= 50 ; itt++) {
//				test = test.add(new BigInteger(StringUtils.reverse(test.toString())));
				test += NumbersLib.reverseDigits(test);
				if (NumbersLib.isPalindrome(test)) {
					isLych = false;
					break;
				}
			}
			if (isLych) {
				count++;
				lychNumbers.add(n);
			}
		}
		return count + "\t" + lychNumbers;
	}
	

}
